#ifndef UNIT_H
#define UNIT_H

#include <QRect>
#include <QPixmap>
#include <QPainter>
#include <QDebug>
#include <QVector>


class Unit
{
public:
    enum Type {Block, Fruit, Door, Player, Monster, Rock};

    Unit();
    Unit(QRect &geometry);
    virtual ~Unit();

    QRect getGeometry();
    void getGeometry(int &left, int &top, int &right, int &bottom);
    int getLives();
    virtual int getType() const = 0;

    void setgeometry(QRect &geometry);
    void setgeometry(int left, int top, int width, int height);
    void setLives(int lives);

    void init();
    virtual void loadPixmaps() = 0;
    void loseALife();
    void gainALife();
    bool isDead();
    bool collidesWith(Unit *unit);
    virtual void draw(QPainter *painter) = 0;
    virtual void serializeDebug(QDebug &dbg);
    virtual void serializeOut(QDataStream &out);
    virtual void serializeIn(QDataStream &in);

protected:
    QRect m_geometry;
    int m_lives;
    int m_step;
    QVector< QVector<QPixmap> > m_pixmaps;
};


QDataStream & operator << (QDataStream &out, Unit* unit);
QDataStream & operator >> (QDataStream &in,  Unit* unit);
QDebug operator<<(QDebug dbg, Unit *unit);


#endif // UNIT_H
